//@author A0097978X
package flexiCommands;

import static org.junit.Assert.*;

import org.junit.Test;

import storage.TimeRange;
import storage.Time;
import storage.DateRange;
import storage.Date;

public class FlexiTest {
	
	@Test
	public void testAddCommands() throws Exception {
	/*
	 * Test Case: Adding a line of description
	 * 			  add [Description]
	 */
		Command actual = FlexiCommandGenerator.generateCommands("add hello");
		String actualDescription = actual.getDescription();
		
		Command expected = new Command();
		expected.setDescription("hello");													//set description to "hello"
		String expectedDescription = expected.getDescription();

		assertEquals(expectedDescription, actualDescription);
		
	/*
	 * Test Case: Adding a date range
	 * 			  add [Start Date] [End Date]
	 */
		actual = FlexiCommandGenerator.generateCommands("add 1 Oct 9 Oct");
		DateRange actualDateRange = actual.getDateRange();
		
		expected = new Command();
		expected.setDateRange(new DateRange(new Date(2014, 10, 1), new Date(2014, 10, 9))); //set 1 to 9 October 2014
		DateRange expectedDateRange = expected.getDateRange();
		
		assertEquals(expectedDateRange, actualDateRange);
	
	/*
	 * Test Case: Adding a specific date
	 * 			  add [End Date]
	 */
		actual = FlexiCommandGenerator.generateCommands("add 10 October");
		Date actualEndDate = actual.getEndDate();
		
		expected = new Command();
		expected.setDateRange(new DateRange(new Date(), new Date(2014, 10, 10)));			//set 10 October 2014
		Date expectedEndDate = expected.getEndDate();
		
		assertEquals(actualEndDate, expectedEndDate);		
		
	/*
	 * Test Case: Adding a relative date
	 * 			  add [Relative Date]
	 */
		actual = FlexiCommandGenerator.generateCommands("add tomorrow");
		Date actualEndDate2 = actual.getEndDate();
		
		expected = new Command();
		int day_tomorrow = Clock.getCurrentDate().getDay()+1;								//set 1 day after today
		int month_tomorrow = Clock.getCurrentDate().getMonth();
		int year_tomorrow = Clock.getCurrentDate().getYear();
		Date tomorrow = new Date(year_tomorrow, month_tomorrow, day_tomorrow);
		expected.setDateRange(new DateRange(new Date(), tomorrow));			
		Date expectedEndDate2 = expected.getEndDate();
			
		assertEquals(expectedEndDate2, actualEndDate2);	
		
	/*
	 * Test Case: Adding a time range
	 * 			  add [Start Time] [End Time]
	 */
		actual = FlexiCommandGenerator.generateCommands("add 4 to 6:30pm");
		TimeRange actualTimeRange = actual.getTimeRange();
			
		expected = new Command();
		expected.setTimeRange(new TimeRange(new Time(16, 0), new Time(18, 30)));  			//set 4pm to 6pm
		TimeRange expectedTimeRange = expected.getTimeRange();
			
		assertEquals(expectedTimeRange, actualTimeRange);
		
	/*
	 * Test Case: Adding a specific time
	 * 			  add [End Time]
	 */
		actual = FlexiCommandGenerator.generateCommands("add 10:30pm");
		Time actualEndTime = actual.getEndTime();
		
		expected = new Command();
		expected.setTimeRange(new TimeRange(new Time(), new Time(22, 30)));					//set 10:30pm
		Time expectedEndTime = expected.getEndTime();
		
		assertEquals(expectedEndTime, actualEndTime);	
	
	/*
	 * Test Case: Adding a relative time
	 * 			  add [Relative Time]
	 */
		actual = FlexiCommandGenerator.generateCommands("add in 5 hours");
		Time actualEndTime2 = actual.getEndTime();
			
		expected = new Command();
		int hour_relative = Clock.getCurrentTime().getHour()+5;								//set 5 hours later
		int minute_relative = Clock.getCurrentTime().getMinute();
		Time relative = new Time(hour_relative, minute_relative);
		expected.setTimeRange(new TimeRange(new Time(), relative));			
		Time expectedEndTime2 = expected.getEndTime();
				
		assertEquals(expectedEndTime2, actualEndTime2);
	}
	
	@Test
	public void testEditCommands() throws Exception {
	/*
	 * Test Case: Modifying/adding to description
	 * 			  edit [Task ID] [Description]
	 */
		Command actual = FlexiCommandGenerator.generateCommands("edit 1 new name");
		String actualDescription = actual.getDescription();
		int actualOption = actual.getOption();												//get option that is 1
		
		
		Command expected = new Command();
		expected.setDescription("new name");												//set description to "new name"
		String expectedDescription = expected.getDescription();
		expected.setOption(1);
		int expectedOption = expected.getOption();

		assertEquals(expectedDescription, actualDescription);	
		assertEquals(expectedOption, actualOption);
	
	/*
	 * Test Case: Modifying/adding to end time
	 * 			  edit [Task ID] [End Time]
	 */
		actual = FlexiCommandGenerator.generateCommands("edit 5 end time 2pm");
		Time actualEndTime = actual.getEndTime();
		int actualOption2 = actual.getOption();												//get option that is 5
			
			
		expected = new Command();
		expected.setTimeRange(new TimeRange(new Time(), new Time(14, 0)));												//set description to "new name"
		Time expectedEndTime = expected.getEndTime();
		expected.setOption(5);
		int expectedOption2 = expected.getOption();

		assertEquals(expectedEndTime, actualEndTime);	
		assertEquals(expectedOption2, actualOption2);
	}
	
	@Test
	public void testDisplayCommands() throws Exception {
	/*
	 * Test Case: Displaying/searching from list
	 * 			  display [Query]
	 */
		Command actual = FlexiCommandGenerator.generateCommands("display meeting");
		String actualQuery = actual.getQuery();
		
		Command expected = new Command();
		expected.setQuery("meeting");														//set query to meeting
		String expectedQuery = expected.getQuery();
		
		assertEquals(actualQuery, expectedQuery);
	}
	
	@Test
	public void testRemoveCommands() throws Exception {
	/*
	 * Test Case: Removing/deleting a task
	 * 			  remove [Task ID]
	 */
		Command actual = FlexiCommandGenerator.generateCommands("remove 1");
		int actualOption = actual.getOption();
			
		Command expected = new Command();
		expected.setOption(1);																//set option to 1
		int expectedOption = expected.getOption();
			
		assertEquals(actualOption, expectedOption);
		
	/*
	 * Test Case: Removing/deleting all tasks
	 * 			  remove [Special Command]
	 */
		actual = FlexiCommandGenerator.generateCommands("remove all");
		String actualQuery = actual.getQuery();
		
		expected = new Command();
		expected.setQuery("all");															//set query to all
		String expectedQuery = expected.getQuery();
		
		assertEquals(actualQuery, expectedQuery);
	}
	
	@Test
	public void testCompleteCommands() throws Exception {
	/*
	 * Test Case: Completing a task from list
	 * 			  complete [Task ID]
	 */
		Command actual = FlexiCommandGenerator.generateCommands("complete 2");
		int actualOption = actual.getOption();
		
		Command expected = new Command();
		expected.setOption(2);																//set option to 2
		int expectedOption = expected.getOption();
			
		assertEquals(actualOption, expectedOption);
		
	/*
	 * Test Case: Completing all pending task
	 * 			  complete [Special Command]
	 */
		actual = FlexiCommandGenerator.generateCommands("complete pending");
		String actualQuery = actual.getQuery();
			
		expected = new Command();
		expected.setQuery("pending");														//set query to pending
		String expectedQuery = expected.getQuery();
			
		assertEquals(actualQuery, expectedQuery);
	}
	
	@Test
	public void testPendingCommands() throws Exception {
	/*
	 * Test Case: Pending a task from list
	 * 			  pending [Task ID]
	 */
		Command actual = FlexiCommandGenerator.generateCommands("pending 6");
		int actualOption = actual.getOption();
			
		Command expected = new Command();
		expected.setOption(6);																//set option to 6
		int expectedOption = expected.getOption();
				
		assertEquals(actualOption, expectedOption);
			
	/*
	 * Test Case: Pending all pending task
	 * 			  pending [Special Command]
	 */
		actual = FlexiCommandGenerator.generateCommands("pending complete");
		String actualQuery = actual.getQuery();
				
		expected = new Command();
		expected.setQuery("complete");														//set query to complete
		String expectedQuery = expected.getQuery();
				
		assertEquals(actualQuery, expectedQuery);
	}
	
	@Test
	public void testUndoCommands() throws Exception {
	/*
	 * Test Case: Undo last action
	 * 			  undo
	 */
		Command actual = FlexiCommandGenerator.generateCommands("undo");
		String actualCommandType = actual.getCommandType();
				
		Command expected = new Command();
		expected.setCommandType("undo");
		String expectedCommandType = expected.getCommandType();
					
		assertEquals(actualCommandType, expectedCommandType);
	}
	
	@Test
	public void testRedoCommands() throws Exception {
	/*
	 * Test Case: Undo last action
	 * 			  undo
	 */
		Command actual = FlexiCommandGenerator.generateCommands("redo");
		String actualCommandType = actual.getCommandType();
					
		Command expected = new Command();
		expected.setCommandType("redo");
		String expectedCommandType = expected.getCommandType();
						
		assertEquals(actualCommandType, expectedCommandType);
	}
	
	public void testExitCommands() throws Exception {
	/*
	 * Test Case: Undo last action
	 * 			  undo
	 */
		Command actual = FlexiCommandGenerator.generateCommands("exit");
		String actualCommandType = actual.getCommandType();
						
		Command expected = new Command();
		expected.setCommandType("exit");
		String expectedCommandType = expected.getCommandType();
							
		assertEquals(actualCommandType, expectedCommandType);
	}
}
